//轮播图///////////////////////////////////////

//////////////////////////////////////////////////

// let tab=document.querySelector('')
//顶部选项我的京东
// console.log($(".ul1 li"));
$(".ul1 li a").mouseenter(function () {
  let index = $(this).index();
  $(".ul1 li a").css("color", "rgb(153, 153, 153");
  $(this).eq(index).css("color", "red");
});
$(".my").mousemove(function () {
  $(".my-jd").show();
});
$(".my").mouseout(function () {
  $(".my-jd").hide();
});
//导航换颜色
$(".my-jd >span").mousemove(function () {
  $(this).css("color", "red");
});
$(".my-jd >span").mouseout(function () {
  $(this).css("color", "");
});
//京东小超市显示隐藏
let imgA = document.querySelector(".fs_act_lk_img");
let imgB = document.querySelector(".bannerImg");
imgA.onmousemove = function () {
  imgB.style.width = "790px";
};
imgA.onmouseout = function () {
  imgB.style.width = 0;
};
$(".cate li").hover(
  function () {
    let index = $(this).index();
    $(this).css("background", "rgb(217, 217, 217)");
  },
  function () {
    $(this).css("background", "");
  }
);

//轮播图旁ul显示隐藏
let mainObj = {
  obj1: {
    arr1: [
      "家电馆",
      "家电专卖店",
      "家电服务",
      "企业采购",
      "商用电器",
      "高价回收",
    ],
    arr2: [
      "电视",
      "空调",
      "洗衣机",
      "冰箱",
      "厨卫大电",
      "厨房小电",
      "生活电器",
      "个护健康",
      "视听影音",
    ],
  },
  obj2: {
    arr1: ["手机频道", "网上营业厅", "配件频道", "智能数码", "影响Clib"],
    arr2: [
      "手机通讯",
      "运营商",
      "手机配件",
      "摄影摄像",
      "数码配件",
      "影音娱乐",
      "电子教育",
    ],
  },
  obj3: {
    arr1: ["电脑办公", "企业采购", "GAME+", "装机大师", "企业租赁"],
    arr2: [
      "电脑整机",
      "电脑配件",
      "外设产品",
      "游戏设备",
      "网络产品",
      "办公设备",
      "文具",
      "耗材",
      "服务产品",
    ],
  },
  obj4: {
    arr1: [
      "家装城",
      "居家日用",
      "精品家具",
      "家装建材",
      "国际厨具",
      "装修服务",
      "企业采购",
    ],
    arr2: [
      "厨具",
      "家纺",
      "生活日用",
      "家装软饰",
      "灯具",
      "家具",
      "全屋定制",
      "建筑材料",
      "厨房卫浴",
      "五金电工",
      "装修设计",
    ],
  },
  obj5: {
    arr1: ["男装", "女装", "内衣", "童装童鞋", "服饰企业购"],
    arr2: ["女装", "男装", "内衣", "配饰", "童装", "童鞋"],
  },
  obj6: {
    arr1: [
      "清洁用品",
      "美妆馆",
      "个护馆",
      "妆比社",
      "京东国际美妆",
      "宠物馆",
      "美妆企业购",
    ],
    arr2: [
      "面部护肤",
      "香水彩妆",
      "男士护肤",
      "洗发护发",
      "口腔护理",
      "身体护理",
      "女性护理",
      "纸品清洗",
      "家庭清洁",
      "宠物生活",
    ],
  },
  obj7: {
    arr1: [
      "自营鞋靴",
      "自营箱包",
      "时尚鞋包",
      "潮流珠宝",
      "奢侈品",
      "时尚K金",
      "黄金企业购",
      "鞋包企业购",
    ],
    arr2: [
      "时尚女鞋",
      "潮流女包",
      "精品男包",
      "功能箱包",
      "奢侈品",
      "精选大牌",
      "钟表",
      "珠宝首饰",
      "金银投资",
    ],
  },
  obj8: {
    arr1: [
      "体育服务",
      "运动城",
      "户外馆",
      "健身房",
      "骑行馆",
      "钟表城",
      "钟表企业购",
    ],
    arr2: [
      "流行男鞋",
      "运动鞋包",
      "运动服饰",
      "健身训练",
      "骑行运动",
      "体育用品",
      "户外鞋服",
      "户外装备",
      "垂钓用品",
      "游泳用品",
    ],
  },
  obj9: {
    arr1: ["全新汽车", "车管家", "旗舰店", "新车装备", "直营店", "油卡充值"],
    arr2: [
      "房产",
      "汽车车型",
      "汽车价格",
      "汽车品牌",
      "维修保养",
      "汽车装饰",
      "车载电器",
      "美容清洗",
      "安全自驾",
      "汽车服务",
      "电动车",
    ],
  },
  obj10: {
    arr1: ["母婴", "玩具乐器", "奶粉馆", "尿裤馆", "潮流珠宝", "京东国际母婴"],
    arr2: [
      "奶粉",
      "营养辅食",
      "尿裤湿巾",
      "尿裤湿巾",
      "喂养用品",
      "洗护用品",
      "妈妈专区",
      "童车童床",
      "寝居服饰",
      "玩具",
    ],
  },
  obj11: {
    arr1: ["食品饮料", "酒类", "地方特产", "京东国际美食"],
    arr2: [
      "新鲜水果",
      "蔬菜蛋品",
      "精选肉类",
      "海鲜水产",
      "冷饮冻食",
      "中外名酒",
      "进口食品",
      "休闲食品",
      "地方特产",
      "茗茶",
      "饮料冲调",
      "粮油调味",
    ],
  },
  obj12: {
    arr1: ["京东礼品", "火机烟具", "鲜花", "京东农服", "同城绿植", "园林园艺"],
    arr2: [
      "艺术品",
      "火机烟具",
      "礼品",
      "鲜花速递",
      "绿植园艺",
      "绿植园艺",
      "农药",
      "肥料",
      "畜牧养殖",
      "农机农具",
    ],
  },
  obj13: {
    arr1: [
      "专科用药",
      "滋补养生",
      "膳食补充",
      "健康检测",
      "两性情话",
      "亮眼视界",
    ],
    arr2: [
      "中西药品",
      "营养健康",
      "营养成分",
      "滋补养生",
      "计生情趣",
      "保健器械",
      "护理护具",
      "隐形眼镜",
      "健康服务",
    ],
  },
  obj14: {
    arr1: ["图书", "文娱", "教育培训", "电子书", "文娱寄卖商城"],
    arr2: [
      "文学",
      "童书",
      "教材教辅",
      "人文社科",
      "经管离职",
      "艺术",
      "科学技术",
      "生活",
      "刊/原版",
      "文娱影像",
      "教育培训",
      "电子书",
      "邮币",
    ],
  },
  obj15: {
    arr1: [
      "本周热推",
      "精选酒店",
      "特惠机票",
      "主题乐园",
      "电影票",
      "会议团建",
    ],
    arr2: [
      "交通出行",
      "酒店预订",
      "旅游度假",
      "定制旅游",
      "演出票务",
      "生活缴费",
      "生活服务",
      "彩票",
      "游戏",
      "海外生活",
    ],
  },
  obj16: {
    arr1: ["金融首页", "0元评测"],
    arr2: ["理财", "众筹", "东家", "白条", "支付", "保险", "股票"],
  },
  obj17: {
    arr1: [
      "京东服务",
      "京东小家",
      "安装服务",
      "维修服务",
      "清洗保养",
      "七月服务",
      "特色服务",
    ],
    arr2: [
      "家电安装",
      "办公安装",
      "家电安装",
      "家电维修",
      "手机维修",
      "办公维修",
      "数码维修",
      "清洗保养",
      "特色服务",
      "二手数码",
      "二手电脑",
      "二手奢品",
      "二手书",
    ],
  },
  obj18: {
    arr1: ["元器件", "企业转", "PLUS会", "贡品优", "企业"],
    arr2: [
      "工具",
      "劳动防",
      "安全消",
      "工控配",
      "仪器仪",
      "清洁用",
      "化学",
      "仓储包",
      "焊接禁锢",
      "机械配件",
      "暖通照明",
      "实验用品",
    ],
  },
};
//
$(".fs_inner .nav .cate li").mouseenter(function () {
  let num = this.getAttribute("data-num");
  $(".obj").show();
  let obj = mainObj[`obj${num}`];
  let ulStr1 = "";
  obj.arr1.forEach((v) => {
    ulStr1 += `<li>${v}</li>`;
  });
  document.querySelector(".fs_inner .top-ul").innerHTML = ulStr1;
  let ulStr2 = "";
  obj.arr2.forEach((v) => {
    ulStr2 += `<li><b>${v}</b>
      <span>电视机</span><span>电视机</span><span>电视机</span>
      <span>电视机</span><span>电视机</span><span>电视机</span></li>`;
  });
  document.querySelector(".fs_inner .cate .left-ul").innerHTML = ulStr2;
});
$(".fs_inner .nav li").mouseleave(function () {
  $(".obj").hide();
});

//倒计时
var box3 = document.getElementById("box3");
box3.style.color = "white";
box3.style.lineHeight = "3";
var box2 = document.getElementById("box2");
box2.style.color = "white";
box2.style.lineHeight = "3";
var box1 = document.getElementById("box1");
box1.style.color = "white";
box1.style.lineHeight = "3";
setInterval(function () {
  var d4 = new Date("2022-1-20 21:00:00");
  var now = new Date();
  var times = d4.getTime() / 1000 - now.getTime() / 1000; //d4和now相差的秒数
  var hours = parseInt(times / 60 / 60);
  hours = hours < 10 ? "0" + hours : hours;
  var fen = parseInt((times / 60) % 60); //相差分钟数
  fen = fen < 10 ? "0" + fen : fen;
  var miao = parseInt(times % 60); //相差秒
  miao = miao < 10 ? "0" + miao : miao;
  box3.innerHTML = miao;
  box2.innerHTML = fen;
  box1.innerHTML = hours;
}, 1000);

// 选项卡换颜色 a标签
$(".tj-top  ul li a").hover(
  function () {
    $(this).css("color", "red");
    $(this).css("borderBottom", "2px solid red");
  },
  function () {
    $(this).css("borderBottom", "");
    $(this).css("color", "");
  }
);
// 选项卡
function List() {
  this.SPAN = function () {
    this.spans = document.querySelectorAll(".xxk");
    this.uls = document.querySelectorAll(".tj-bt");
    this.pageNum = 0;
    this.spans.forEach((v, i) => {
      v.onmouseover = () => {
        v.classList.add("active");
        this.spans[this.pageNum].classList.remove("active");
        this.uls[this.pageNum].style.display = "none";
        this.uls[i].style.display = "block";
        this.pageNum = i;
      };
    });
  };
}
let lt = new List();
lt.SPAN();

//导航条

//JOY寻宝////////////////////////////////////////////////////////
$(".J_newArrival1 .tab_head span").hover(
  function () {
    $(this).css("background", "red");
    $(this).css("color", "white");
  },
  function () {
    $(this).css("color", "");
    $(this).css("background", "");
  }
);

//侧边栏//////relative//////////////////////////////////////////////////////

let cbl = document.querySelector(".cebianlan");
let search = document.querySelector(".search-btn ");
document.addEventListener("scroll", function () {
  let y = window.pageYOffset;
  // console.log(y);
  if (y > 1035) {
    search.style.display = "block";
    cbl.style.position = "fixed";
    cbl.style.top = 100 + "px";
    cbl.style.right = 260 + "px";
  } else if (y < 1035) {
    cbl.style.position = "absolute";
    search.style.display = "none";
    cbl.style.top = 1037 + "px";
    cbl.style.right = 260 + "px";
  }
});

/////////////////商品接口////////////////////////////////////

/* 所有商品接口
get
参数
pagesize  每页获取几个数据
pagenum 获取第几页数据
uid  用户id
http://jx.xuzhixiang.top/ap/api/allproductlist.php?pagesize=20&pagenum=4 */
let username = localStorage.getItem("username");
let id = localStorage.getItem("id");
let token = localStorage.getItem("token");
let nextP = document.querySelector(".next-p");
let shang = document.querySelector(".shang-p");
let num = 0;
nextP.onclick = function () {
  num++;
  load();
};
shang.onclick = function () {
  num--;
  load();
};

load();
function load() {
  let pagesize = 40;
  let pagenum = 0;
  let API = "http://jx.xuzhixiang.top/ap/api/allproductlist.php";
  axios.get(API, { params: { pagenum: num, pagesize } }).then((res) => {
    // console.log(res.data.data);
    let str = "";
    let strUser = "";
    let Parr = res.data.data;
    Parr.forEach((v) => {
      str += `
      <a href="商品详情.html?id=${v.pid}"><li>
      <img src="${v.pimg}" alt="">
      <p>${v.pname}</p>
      <p>$${v.pprice}</p>
      <span>查看详情</span>
    </li></a>
      `;
    });
    let productUl = document.querySelector(".product-ul");
    productUl.innerHTML = str;

    if (localStorage.getItem("id")) {
      $(".box-user b").css("display", "none");
      let User = document.querySelector("#User");
      let userName = localStorage.getItem("username");
      User.innerHTML = "亲爱的" + userName;
    }
  });
}
